home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / i / internet / software / tuwtcpsr / cookie.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-06  |  1.5 KB  |  69 lines

  1. #include <stdlib.h>
  2. #include <tos.h>
  3. #include "cookie.h"
  4. #include "mbuf.h"
  5. #include <stdio.h>
  6. #ifndef NULL
  7. #define NULL (void *)0L
  8. #endif
  9. #define _cookiejar    *(long *)0x5A0L
  10.  
  11. COOKIE *new_cookiejar(long n)
  12. {
  13.   register COOKIE *jar,*newjar;
  14.   register long i,c;
  15.  
  16.   jar = get_cookiejar();
  17.   i=0;
  18.   if(jar) for(; jar[i].id != ENDCOOKIE; i++);  /* get size of old jar */
  19.   if(jar && jar[i].val > n) return(jar);  /* there isroom in jar */
  20.  
  21.   newjar = (COOKIE *)getmem(n*sizeof(COOKIE));/* alloc new jar */
  22.   if(jar && newjar) for(c=0; c<i; c++)
  23.   {  /* copy old jar */
  24.     newjar[c].id = jar[c].id;
  25.     newjar[c].val = jar[c].val;
  26.   }
  27.   newjar[i].id = ENDCOOKIE;  /* terminate new jar */
  28.   newjar[i].val = n;
  29.   _cookiejar = (long)newjar;  /* install new jar */
  30.   return(newjar);
  31. }
  32.  
  33. COOKIE *get_cookiejar(void)
  34. {
  35.   register long cookieaddress;
  36.   
  37.     cookieaddress = _cookiejar;  /* return address of cookiejar */
  38.     return (COOKIE *)cookieaddress;
  39. }
  40.  
  41. COOKIE *add_cookie(long id,long val)
  42. {
  43.   register COOKIE *jar;
  44.  
  45.  
  46.  
  47.   if((jar = new_cookiejar(8L))==NULL) return(NULL);
  48.     while(jar->id != ENDCOOKIE) jar++;  /* search end of cookiejar */
  49.     jar->id = id;
  50.     (jar+1)->val = jar->val;  /* keep size of jar */
  51.     jar->val = val;
  52.     (jar+1)->id = ENDCOOKIE;
  53.   return(jar);
  54. }
  55.  
  56.  
  57. COOKIE *get_cookie(long id)
  58. {
  59.   register COOKIE *jar;
  60.   if((jar = get_cookiejar()) == NULL) return(NULL);
  61.   while(jar->id)
  62.   {
  63.     if(jar->id == id) return(jar);  /* find cookie */
  64.     jar++;
  65.   }
  66.   return(NULL);
  67. }
  68.  
  69.